import { dbUtils } from '../core'

export const userProfileRepository = {
    insert(storeUserId: string, profileData: string): void {
        dbUtils.execute(
            `INSERT OR REPLACE INTO user_profiles (store_user_id, profile_data, updated_at)
             VALUES (?, ?, CURRENT_TIMESTAMP)`,
            [storeUserId, profileData]
        )
    },

    getByStoreUserId(storeUserId: string): string | null {
        const row = dbUtils.queryOne(
            `SELECT profile_data FROM user_profiles WHERE store_user_id = ?`,
            [storeUserId]
        )
        return row?.profile_data || null
    },

    getAll(): Array<{ store_user_id: string; profile_data: string }> {
        return dbUtils.query(
            `SELECT store_user_id, profile_data FROM user_profiles ORDER BY updated_at DESC`
        )
    }
}

export default userProfileRepository




